﻿using System;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using ZSZ.Application;
using ZSZ.Core.Entities;
using ZSZ.EntityFramework;

namespace ZSZ.AdminWeb.Seed
{
    public class SeedData
    {
        public static void Initialize(IServiceProvider app)

        {

            var _dbContext = app.GetRequiredService<ZSZDbContext>();

            var unitWork = new UnitOfWork(_dbContext);

            using (unitWork)
            {
                var dataList = unitWork.AdminUserService.GetAllDataEntity();
                if (dataList.Any())
                {
                    //有数据则返回
                    return;
                }
                else
                {
                    //添加User测试数据
                    unitWork.AdminUserService.AddAdminUser("GuDuYing", "13189735977", "123456", "2272247436@qq.com",
                        null);
                    unitWork.SaveChange();
                }
            }

        }

    }
}